
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.Timer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ilstxfe
 */
public class Core {
    private ArrayList<TaskElement> downQueue;
    private ArrayList<TaskElement> upQueue;
    private ArrayList<TaskElement> taskQueue;
    private int currentLevel;
    private boolean isUp;
    private Timer timer;
    private int delay;

    private ActionListener StateListener = new ActionListener(){
        public void actionPerformed(ActionEvent e) {
            if(isUp){
                currentLevel++;
                
            }
            else{
                currentLevel--;
            }
        }
    };

    public Core(){
        downQueue = new ArrayList<TaskElement>();
        upQueue = new ArrayList<TaskElement>();
        taskQueue = new ArrayList<TaskElement>();
        currentLevel = 0;
        isUp = true;
        delay = 1000;
        timer = new Timer(delay, StateListener);
    }   

    public void addTask(TaskElement newTask){
        taskQueue.add(newTask);

        int source = newTask.getSource();
        int dest = newTask.getDest();

        if(source <= currentLevel && dest <= currentLevel && !isUp){     //elevator is downward
            downQueue.add(newTask);
        }
        else if(source >= currentLevel && dest >= currentLevel && isUp){       //elevator is upward
            upQueue.add(newTask);
        }
    }

    public void removeTask(){

    }

    public int getCurrentLevel(){
        return currentLevel;
    }

    





}
